package org.example.controller;


import org.example.model.Article;
import org.example.service.ArticleService;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private UserService userService;

    @RequestMapping("/select/articles")
    public Object selectArticlesAndUsers(){
            List<Article> articles = articleService.selectArticlesAndUsers();
            return articles;
    }

    @RequestMapping("/test")
    @Transactional
    public Object test(boolean error){

        articleService.update();
        userService.update(error);
        //只要不抛异常，就修改成功
        return true;
//        return articleService.test(error);
    }
}
